package com.qymerge.manage.base.service.impl;

import com.qymerge.manage.base.dao.IMetaLogsDao;
import com.qymerge.manage.base.ro.MetaLogsRO;
import com.qymerge.manage.base.service.IMetaLogsService;
import com.qymerge.manage.core.bean.ActionResultRO;
import com.qymerge.manage.core.bean.DataTableRO;
import com.qymerge.manage.core.bean.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 *<p>Title: CardServiceImpl</p>
 *<p>Description: 优惠券管理</p>
 *
 *@Author cong.zhang
 *@Version 1.0.0
 *@Date 2020/12/19
 *@Time 17:53
 */
@Service
public class MetaLogsServiceImpl implements IMetaLogsService {

    @Autowired
    private IMetaLogsDao metaLogsDao;

    /**
     * 用户管理-查询
     *
     * @param ro
     * @param pageRequest
     * @return
     */
    @Override
    public DataTableRO list(MetaLogsRO ro, PageRequest pageRequest) {
        List list = metaLogsDao.list(ro, pageRequest);
        DataTableRO dataTableRO = new DataTableRO();
        int allCount = metaLogsDao.total(ro);
        int pageSize = pageRequest.getSize();
        dataTableRO.setAll_count(allCount);
        dataTableRO.setList(list);
        dataTableRO.setCurrent_page(pageRequest.getPage());
        dataTableRO.setPage_size(pageSize);
        int allPage = (allCount % pageSize == 0 ? allCount / pageSize : allCount / pageSize + 1);
        dataTableRO.setAll_page(allPage);
        return dataTableRO;
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public MetaLogsRO detail(Long id) {
        return metaLogsDao.findOne(id);
    }

    /**
     * 新增
     *
     * @param ro
     * @return
     */
    @Override
    public ActionResultRO save(MetaLogsRO ro) {
        int rn = 0;
        if (ro.getId() == 0) {
            rn = metaLogsDao.install(ro);
        } else {
            rn = metaLogsDao.update(ro);
        }
        return new ActionResultRO(rn, ro.getId() == 0 ? "保存成功" : "修改成功", ro.getId() == 0 ? "保存失败" : "修改失败");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @Override
    public ActionResultRO delete(Long[] ids) {
        int rn = metaLogsDao.remove(Arrays.asList(ids));
        return new ActionResultRO(true, "删除" + rn +"成功", "删除" + rn +"失败");
    }


}
